/*
 * 文 件 名:  ${tableName}ManagerImpl.java
 * 版   权: Copyright www.${company}.com Corporation ${dateYear} 版权所有
 * 描     述:  <描述>
 * 修 改 人:  mingbao
 * 修改时间:  ${dateTime}
 * 跟踪单号: <跟踪单号>
 * 修改单号: <修改单号>
 * 修改内容: <修改内容>
 */
package com.${company}.${projectName}.manager.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.lang.Exception;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.teshehui.framework.util.page.Page;
import com.${company}.${projectName}.model.${tableName}Model;
import com.${company}.${projectName}.manager.${tableName}Manager;
import com.${company}.${projectName}.service.${tableName}Service;

/**
 * <一句话功能简述>
 * <功能详细描述>
 * 
 * @author  mingbao
 * @version  [版本号, ${dateTime}]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
@Service("${tableNameMin}Manager")
public class ${tableName}ManagerImpl implements ${tableName}Manager
{
    private static final Log    logger = LogFactory.getLog(${tableName}ManagerImpl.class);

    @Resource
    private ${tableName}Service ${tableNameMin}Service;

    public void add${tableName}(${tableName}Model ${tableNameMin}Model)
    {
    	String params="";
    	try {
    		params=JSON.toJSONString(${tableNameMin}Model);
		} catch (Exception e) {
			// TODO: handle exception
		}		
        if (logger.isDebugEnabled())
        {
            logger.debug("--Params-->" + params);
        }
        if (${tableNameMin}Model!=null)
        {
           try{
            ${tableNameMin}Service.add${tableName}(${tableNameMin}Model);
            }catch(Exception e){
                logger.error("新增${tableName}异常,Params:"+params, e);
            }
        }
    }

    public void update${tableName}ById(${tableName}Model ${tableNameMin}Model)
    {
    	String params="";
    	try {
    		params=JSON.toJSONString(${tableNameMin}Model);
		} catch (Exception e) {
			// TODO: handle exception
		}
        if (logger.isDebugEnabled())
        {
            logger.debug("--更新${tableName} Params-->" + params);
        }
        if (${tableNameMin}Model!=null)
        {
           try{
            ${tableNameMin}Service.update${tableName}ById(${tableNameMin}Model);
            }catch(Exception e){
                logger.error("更新${tableName}异常,Params:"+params, e);
            }
        }

    }

    public ${tableName}Model get${tableName}ById(String id)
    {
    	${tableName}Model result = null;
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName}ById Params-->" + id);
        }
        if (!StringUtils.isEmpty(id))
        {
            try{
            ${tableName}Model ${tableNameMin}Model=new ${tableName}Model();
            ${tableNameMin}Model.setId(Long.parseLong(id));
            result = ${tableNameMin}Service.get${tableName}ById(${tableNameMin}Model);
            }catch(Exception e){
                logger.error("get${tableName}ById异常,Params:"+id, e);
            }
        }
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName}ById result-->" + JSON.toJSONString(result));
        }
        return result;
    }

    public Map<String, Object> get${tableName}(${tableName}Model ${tableNameMin}Model,Page page)
    {
        
        Map<String, Object> result = new HashMap<String, Object>();      
        String params="";
    	try {
    		params=JSON.toJSONString(${tableNameMin}Model)+JSON.toJSONString(page);
		} catch (Exception e) {
			// TODO: handle exception
		}
        if (logger.isDebugEnabled())
        {
            logger.debug("--get${tableName} Params-->" + params);
        }
        try{
        if (${tableNameMin}Model!=null)
        {          
            List<${tableName}Model> list = ${tableNameMin}Service.get${tableName}(${tableNameMin}Model,page);
            result.put("page", page);
            result.put("list", list);
        }
        }catch(Exception e){
            logger.error("get${tableName}异常,Params:"+params, e);
        }
        if (logger.isDebugEnabled())
        {
            logger.debug("--result-->" + JSON.toJSONString(result));
        }
        return result;
    }

    public void deleteById(String id)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("--deleteById Params-->" + id);
        }
        if (!StringUtils.isEmpty(id))
        {
            try{
            	${tableName}Model ${tableNameMin}Model=new ${tableName}Model();
            	${tableNameMin}Model.setId(Long.parseLong(id));
            ${tableNameMin}Service.deleteById(${tableNameMin}Model);
            }catch(Exception e){
                logger.error("删除${tableName}异常,Params:"+id, e);
            }
        }
    }
    
    @Override
	public void deleteByIds(List<Long> ids) {    
    	String params="";
     	try {
     		params=JSON.toJSONString(ids);
 		} catch (Exception e) {
 			// TODO: handle exception
 		}
		if (logger.isDebugEnabled())
        {
            logger.debug("--deleteByIds Params-->" + params);
        }
        if (!ids.isEmpty())
        {
            try{            	
            	 ${tableNameMin}Service.deleteByIds(ids);
            }catch(Exception e){
                logger.error("批量删除${tableName}异常,Params:"+ params, e);
            }
        }
		
	}

}
